package fordemo

object Test {
    def main(args: Array[String]): Unit = {
        val lara = Person("Lara", false)
        val bob = Person("Bob", true)
        val lucy = Person("Lucy", false, lara, bob)
        val persons = List(lara, bob, lucy)
        // 使用高阶函数
        val res1 = persons.withFilter(p => !p.isMale)
                .flatMap(p => p.children.map(c => (p.name, c.name)))

        println(res1)

        // 使用for

        val res2 = for (p <- persons; if !p.isMale; c <- p.children)
            yield (p.name, c.name)

        println(res2)

    }
}
